package com.kpf.springcloud.controller;

import com.kpf.springcloud.pojo.KpfTopic;
import com.kpf.springcloud.pojo.PageResult;
import com.kpf.springcloud.common.ResultJson;
import com.kpf.springcloud.service.IKpfTopicService;
import com.kpf.springcloud.vo.KpfTopicLikeAndCollectStatusVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author shiwen
 * @date 2021/3/1
 */
@RestController
public class KpfTopicController {

    @Autowired
    private IKpfTopicService kpfTopicService;

    @GetMapping("/topic/getTopicList")
    public ResultJson<PageResult> getTopicList(int pageNum, int pageSize, String title) {
        return ResultJson.ok(kpfTopicService.getTopicList(pageNum, pageSize, title));
    }

    @GetMapping("/topic/getById")
    public ResultJson<KpfTopic> getById() {
        return ResultJson.ok(kpfTopicService.getById());
    }

    @PostMapping("/topic/setTopicId")
    public ResultJson setTopicId(int topicId){
        kpfTopicService.setTopicId(topicId);
        return ResultJson.ok();
    }

    @PostMapping("/topic/editTopic")
    public ResultJson editTopic(String title, String content, String topicMsg) {
        kpfTopicService.editTopic(title, content, topicMsg);
        return ResultJson.ok();
    }

    @GetMapping("/topic/getAllStatusByTopicId")
    public ResultJson<KpfTopicLikeAndCollectStatusVO> getAllStatusByTopicId(int topicId) {
        return ResultJson.ok(kpfTopicService.getAllStatusByTopicId(topicId));
    }

    @GetMapping("/topic/getTopicListByUserId")
    public ResultJson<List<KpfTopic>> getTopicListByUserId() {
        return ResultJson.ok(kpfTopicService.getTopicListByUserId());
    }

    @PostMapping("/topic/deleteTopicById")
    public ResultJson deleteTopicById(int topicId) {
        kpfTopicService.deleteTopicById(topicId);
        return ResultJson.ok();
    }

}